/**
 * 枚举类型定义
 * 与后端 API 保持一致
 */

/**
 * 步骤类型 - StepType
 * 对应后端 API_DOCUMENTATION.md 中的定义
 */
export const StepType = {
  GitClone: 1,      // Git 克隆
  Build: 2,         // 构建
  Test: 3,          // 测试
  Deploy: 4,        // 部署
  DockerBuild: 5,   // Docker 构建
  DockerPush: 6,    // Docker 推送
  K8sDeploy: 7,     // Kubernetes 部署
  NuGetPush: 8,     // NuGet 推送
  MavenDeploy: 9,   // Maven 部署
  CustomScript: 10, // 自定义脚本
} as const
export type StepType = (typeof StepType)[keyof typeof StepType]

/**
 * 任务状态 - TaskStatus
 */
export const TaskStatus = {
  Pending: 0,    // 待执行
  Running: 1,    // 执行中
  Success: 2,    // 成功
  Failed: 3,     // 失败
  Cancelled: 4,  // 已取消
} as const
export type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus]

/**
 * 执行模式 - ExecutionMode
 */
export const ExecutionMode = {
  Serial: 0,    // 串行
  Parallel: 1,  // 并行
} as const
export type ExecutionMode = (typeof ExecutionMode)[keyof typeof ExecutionMode]

/**
 * 触发器类型 - TriggerType
 */
export const TriggerType = {
  Push: 0,         // 代码推送
  PullRequest: 1,  // Pull Request
  Tag: 2,          // 标签创建
} as const
export type TriggerType = (typeof TriggerType)[keyof typeof TriggerType]

/**
 * 日志级别 - LogLevel
 */
export const LogLevel = {
  Debug: 'Debug',
  Info: 'Info',
  Warning: 'Warning',
  Error: 'Error',
} as const
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel]

/**
 * 节点事件类型 - NodeEventType
 */
export const NodeEventType = {
  Registered: 'registered', // 新节点注册
  Online: 'online',         // 节点上线
  Offline: 'offline',       // 节点下线
} as const
export type NodeEventType = (typeof NodeEventType)[keyof typeof NodeEventType]

/**
 * 构建工具类型 - BuildTool
 * 用于自动检测构建命令功能
 */
export const BuildTool = {
  DotNet: 'dotnet',
  Maven: 'maven',
  Gradle: 'gradle',
  NPM: 'npm',
  PNPM: 'pnpm',
  Yarn: 'yarn',
  Cargo: 'cargo',
  Python: 'python',
  Go: 'go',
  PHP: 'php',
  Ruby: 'ruby',
} as const
export type BuildTool = (typeof BuildTool)[keyof typeof BuildTool]

/**
 * 节点能力 - NodeCapability
 */
export const NodeCapability = {
  DotNet: 'dotnet',
  Java: 'java',
  NodeJS: 'nodejs',
  Python: 'python',
  Rust: 'rust',
  Go: 'go',
  Docker: 'docker',
  Kubernetes: 'kubernetes',
  Maven: 'maven',
  Gradle: 'gradle',
  NPM: 'npm',
} as const
export type NodeCapability = (typeof NodeCapability)[keyof typeof NodeCapability]

/**
 * 权限分类 - PermissionCategory
 */
export const PermissionCategory = {
  Workflow: 'Workflow',
  Pipeline: 'Pipeline',
  Node: 'Node',
  System: 'System',
  User: 'User',
  Role: 'Role',
} as const
export type PermissionCategory = (typeof PermissionCategory)[keyof typeof PermissionCategory]

/**
 * 获取任务状态的颜色
 */
export function getTaskStatusColor(status: TaskStatus): string {
  switch (status) {
    case TaskStatus.Pending:
      return 'gray'
    case TaskStatus.Running:
      return 'blue'
    case TaskStatus.Success:
      return 'green'
    case TaskStatus.Failed:
      return 'red'
    case TaskStatus.Cancelled:
      return 'orange'
    default:
      return 'gray'
  }
}

/**
 * 获取任务状态的文本
 */
export function getTaskStatusText(status: TaskStatus): string {
  switch (status) {
    case TaskStatus.Pending:
      return '待执行'
    case TaskStatus.Running:
      return '执行中'
    case TaskStatus.Success:
      return '成功'
    case TaskStatus.Failed:
      return '失败'
    case TaskStatus.Cancelled:
      return '已取消'
    default:
      return '未知'
  }
}

/**
 * 获取步骤类型的文本
 */
export function getStepTypeText(stepType: StepType): string {
  switch (stepType) {
    case StepType.GitClone:
      return 'Git克隆'
    case StepType.Build:
      return '构建'
    case StepType.Test:
      return '测试'
    case StepType.Deploy:
      return '部署'
    case StepType.DockerBuild:
      return 'Docker构建'
    case StepType.DockerPush:
      return 'Docker推送'
    case StepType.K8sDeploy:
      return 'K8s部署'
    case StepType.NuGetPush:
      return 'NuGet推送'
    case StepType.MavenDeploy:
      return 'Maven部署'
    case StepType.CustomScript:
      return '自定义脚本'
    default:
      return '未知'
  }
}

/**
 * 获取日志级别的颜色
 */
export function getLogLevelColor(level: LogLevel): string {
  switch (level) {
    case LogLevel.Debug:
      return 'gray'
    case LogLevel.Info:
      return 'blue'
    case LogLevel.Warning:
      return 'orange'
    case LogLevel.Error:
      return 'red'
    default:
      return 'gray'
  }
}
